package com.northwind.controller;

import com.northwind.dao.LogMapper;
import com.northwind.entity.Log;
import com.northwind.service.LogService;
import com.northwind.util.EasyPOIUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("log")
public class LogController {
    @Resource
    LogService logService;
    @Resource
    LogMapper logMapper;

    @ResponseBody
    @RequestMapping("queryAllPage")
    HashMap<String, Object> queryAllPage(Integer page, Integer rows){
        System.out.println("分页查询的数据为:"+logService.queryAllPage(page, rows));
        return logService.queryAllPage(page, rows);
    }

    @RequestMapping("export")
    public String exportByEasyPOI(){
        List<Log> logs = logMapper.selectAll();

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String nowTime = simpleDateFormat.format(date);

        String newFile = "C://Users//10136//Desktop//"+ nowTime + ".xls" ;
        EasyPOIUtil.export("VideoChannel","管理员操作日志", Log.class, logs,newFile);
        return "forward:/main/main.jsp";
    }
}
